package com.ophiux.websocket.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @desc:
 * @author: hhl
 * @date：2023/9/27 14:27
 */
public class CompletableFutureDemo2 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("主线程开始");

        new Thread(()->{

            System.out.println("开始一个异步县城");
        }).start();

        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("读取文件");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
            }
            return "读取成功..返回结果....";
        });
        CompletableFuture<String> completableFuture1 = completableFuture.thenApply(s -> {
            System.out.println(s);
            return "接收到内容，" + s;
        });
        System.out.println("1111"+completableFuture1.join());

        /*CompletableFuture.supplyAsync(() -> {
            System.out.println("读取文件");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            System.out.println("1读取成功..");
            return "1";
        }).thenApply(s -> {
            System.out.println("2接收到内容，" + s);
            return "2";
        }).thenAccept(y->{
            System.out.println("3.最后综合处理，"+y);
        });*/

        System.out.println("主线程进行中1");
//        Thread.sleep(3000);

    }
}
